﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MyLambda
{
    /// <summary>
    /// 扩展方法: 必须是 静态类 静态方法， 第一个参数前 必须是this 修饰
    /// extendShow.ToInt(ivalue) 调用 可以改为 ivalue.ToInt()
    /// </summary>
    public static class ExtendShow
    {
        public static int ToInt(this int? iParameter)
        {
            return iParameter ?? 0;
        }

        public static void NoShow(this LambdaShow Noshow)
        {
            Console.WriteLine("This is extend NoShow, from LambdaShow Class");
        }

        public static DateTime ToDateTime(this object obj)
        {
            return DateTime.Now;
        }

        public static void Execute(this Action test)
        {
            test();
        }

        public static IEnumerable<TSource> AlbertWhere<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate)
        {
            List<TSource> studentList = new List<TSource>();
            foreach(TSource item in source)
            {
                if(predicate.Invoke(item))
                {
                    studentList.Add(item);
                }
            }
            return studentList;
        }

    }
}
